//
//  WSChapterCell.m
//  CharonTVProject
//
//  Created by karong on 2023/8/8.
//

#import "WSChapterCell.h"
#import "WSChapterVideoCell.h"


@interface WSChapterCell () <UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *listView;
@property (nonatomic, strong) NSArray * dataArray;

@end

@implementation WSChapterCell

- (void)setDataWithObject:(NSArray *)object {
    self.dataArray = object;
    [self.listView reloadData];
}

#pragma mark UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    WSChapterVideoCell * chapterVideoCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WSChapterVideoCell" forIndexPath:indexPath];
    [chapterVideoCell setDataWithObject:self.dataArray[indexPath.row]];
    return chapterVideoCell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = CGSizeZero;
    CGFloat width = floor((WSScreenWidth - 12 - 12 - (5 * 6.5)) / 6.0f);
    size.width = width;
    size.height = 67;
    return size;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(chapterCellDidSelectItemWithObject:)]) {
        [self.delegate chapterCellDidSelectItemWithObject:self.dataArray[indexPath.row]];
    }
}
@end
